#include <climits>
#include <cstdio>

int min(int a, int b);
struct good_info {
    int weight;
    int value;
} data_info[501];
int dp[10001];

int main(int argc, char const* argv[])
{
    int case_num;
    scanf("%d", &case_num);
    for (int k = 0; k < case_num; k++) {
        int empty_weight, full_weight;
        scanf("%d%d", &empty_weight, &full_weight);
        int available_weight = full_weight - empty_weight;
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
            scanf("%d%d", &data_info[i].value, &data_info[i].weight);

        // 初始化，因为要求装入重量恰好等于可装入重量，所以只有dp[0] = 0
        dp[0] = 0;
        for (int i = 1; i <= available_weight; i++)
            dp[i] = INT_MAX;
        //遍历所有种类硬币
        for (int i = 1; i <= n; i++) {
            //完全背包问题，顺序遍历更新
            for (int j = data_info[i].weight; j <= available_weight; j++) {
                if (dp[j - data_info[i].weight] != INT_MAX)
                    dp[j] = min(dp[j], dp[j - data_info[i].weight] + data_info[i].value);
            }
        }
        if (dp[available_weight] != INT_MAX)
            printf("The minimum amount of money in the piggy-bank is %d.\n", dp[available_weight]);
        else
            puts("This is impossible");
    }
    return 0;
}

int min(int a, int b) { return a < b ? a : b; }